package com.faxsun.core.catalog.domain;

import java.io.Serializable;
import java.util.LinkedHashMap;

import org.broadleafcommerce.common.BroadleafEnumerationType;

/**
 * Badges 枚举
 * @author zhaoteng.song@faxsun.com
 *
 */
public class FSBadgesEnum implements BroadleafEnumerationType, Serializable {

	private static final LinkedHashMap<String, FSBadgesEnum> BADGES = new LinkedHashMap<String, FSBadgesEnum>();
	public static final FSBadgesEnum NEW=new FSBadgesEnum("new_badge", "新品");
	public static final FSBadgesEnum TWOBUNDLE = new FSBadgesEnum("badges_2","2罐装");
	public static final FSBadgesEnum FOURBUNDLE = new FSBadgesEnum("badges_4","4罐装");
	public static final FSBadgesEnum SIXBUNDLE = new FSBadgesEnum("badges_6","6罐装");
	public static final FSBadgesEnum EIGHTBUNDLE = new FSBadgesEnum("badges_8","8罐装");
	public static final FSBadgesEnum PROMOTION = new FSBadgesEnum("pro_sell","促销");
	
	public static final FSBadgesEnum NONE=new FSBadgesEnum("","无");
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2724518304391711818L;

	
	/**
	 * CSS class name
	 */
	private String type;

	/**
	 * display name in admin system
	 */
	private String friendlyType;

	@Override
	public String getType() {
		return type;
	}

	@Override
	public String getFriendlyType() {
		return friendlyType;
	}

	public static FSBadgesEnum getInstance(final String type) {
		return BADGES.get(type);
	}

	public FSBadgesEnum(String cssClass, String friendlyName) {

		this.friendlyType = friendlyName;
		setType(cssClass);
	}

	private void setType(final String type) {
		this.type = type;
		if (!BADGES.containsKey(type)) {
			BADGES.put(type, this);
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((friendlyType == null) ? 0 : friendlyType.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FSBadgesEnum other = (FSBadgesEnum) obj;
		if (friendlyType == null) {
			if (other.friendlyType != null)
				return false;
		} else if (!friendlyType.equals(other.friendlyType))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
	
	
}
